package com.changli01.string.exer4;

import org.junit.Test;
//KMP算法
public class countTest {
    public int strCount(String str,String key) {
        int count = 0;
        if(!str.contains(key)) {
            return 0;
        }
        int index = str.indexOf(key);
        while(index != -1) {
            count++;
            index = str.indexOf(key, index+1);
        }


        return count;
    }
    @Test
    public void test() {
        String s1 = "abkkcadkabkebfkabkskab";
        System.out.println(strCount(s1, "ab"));
    }
}
